package com.rmuti.programming.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class ResultGradUI {
//	private Display display;
	private Shell shell;
	
	public ResultGradUI(Display display) {
		shell = new Shell(display);
	}
	
	private void drawHeaderMenu(){
		Display display = shell.getDisplay();
		GridLayout layout = new GridLayout();
		layout.numColumns = 1;
		shell.setLayout(layout);
		shell.setSize(385, 524);

		GridData bgTopMenuLayout = new GridData(385, 55);
		Label label = new Label(shell, SWT.PUSH);
		Image image = new Image(display, "icons/image/header.gif");
		label.setBackgroundImage(image);
		label.setForeground(display.getSystemColor(SWT.COLOR_WHITE));

		GridData layoutText = new GridData();
		layoutText.horizontalAlignment = SWT.CENTER;
		
		label.setLayoutData(layoutText);
		label.setText("ปฏิบัติการเขียนโปรแกรม");
	}
	
	private void drawResultTable(){
		
	}
	
	private void drawButtomMenu(){
		
	}
	
	public void display2(){
		drawHeaderMenu();
	}
	

	public void display(){
		Display display = shell.getDisplay();
		GridLayout layout = new GridLayout();
		layout.numColumns = 1;
		shell.setLayout(layout);
		shell.setSize(385, 524);

		GridData bgTopMenuLayout = new GridData(385, 55);
		Label label = new Label(shell, SWT.PUSH);
		Image image = new Image(display, "icons/image/header.gif");
		label.setBackgroundImage(image);
		label.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
		
//		GridData gridData = new GridData(385, 55);
		GridData layoutText = new GridData();
//		gridData.verticalAlignment = GridData.CENTER;
		layoutText.horizontalAlignment = SWT.CENTER;
		
		label.setLayoutData(layoutText);
		label.setText("ปฏิบัติการเขียนโปรแกรม");
//		label.setAlignment(SWT.CENTER);

		Table table = new Table(shell, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		GridData data = new GridData(350,360);
		table.setLayoutData(data);

		
		String[] titles = { "First Name", "Last Name", "Age" };
		for (int i = 0; i < titles.length; i++) {
			TableColumn column = new TableColumn(table, SWT.NONE);
			column.setText(titles[i]);
			table.getColumn(i).pack();
		}
		
		for (int i = 0 ; i<= 50 ; i++){
			TableItem item = new TableItem(table, SWT.NONE);
			item.setText (0, "Person " +i);
			item.setText (1, "LastName " +i);
			item.setText (2, String.valueOf(i));
		}
		
		for (int i=0; i<titles.length; i++) {
			table.getColumn (i).pack ();
		}
		
		GridData buttomLayout = new GridData(385, 55);
		
		Label buttomLabel = new Label(shell, SWT.PUSH);
		buttomLabel.setBackgroundImage(image);
		buttomLabel.setLayoutData(buttomLayout);
		
//		shell.open();
//		while (!shell.isDisposed()) {
//			if (!display.readAndDispatch())
//				display.sleep();
//		}
//		display.dispose();		
	}
	
	public void open(){
		shell.open();
	}
	
	public Shell getShell(){
		return shell;
	}
	
	public static void main(String[] args) {
		Display display = new Display();
		ResultGradUI gradUI = new ResultGradUI(display);
		gradUI.display2();
		
		Shell shell = gradUI.getShell();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();			
	}
}
